package com.bsierp.util.tags;

import java.util.List;

import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.classic.Session;

import com.bsierp.business.pojo.ColorChart;

import com.bsierp.util.hibernate.HibernateSessionFactory;

public class DisplayColorChartHtmlSelect extends TagSupport {
    
    
    String id;
    String jsFunction;
    
public String getJsFunction() {
        return jsFunction;
    }

    public void setJsFunction(String jsFunction) {
        this.jsFunction = jsFunction;
    }

private Log log = LogFactory.getLog(this.getClass().getName());
 
public int doEndTag( ) throws JspException
{
   
  JspWriter out = pageContext.getOut();
  
  String hql="from ColorChart";

try{
   HttpSession ses = pageContext.getSession();
   boolean isedit=false;
   
   SessionFactory sessionFactory= HibernateSessionFactory.getSessionFactory();
   Session session=sessionFactory.openSession();
   Transaction tx=null;
   String option_str="";
       try {
       tx=session.beginTransaction();
       List l=session.createQuery(hql).list();
       
       for(int i=0;i<l.size();i++){
           ColorChart cc=(ColorChart)l.get(i);
           option_str=option_str+"<option value=\""+cc.getColorchartId()+"\">"+cc.getColorchartName()+"</option>"   ;
           }
       
       }catch(Exception e){
           e.printStackTrace();
           
       }finally{
           session.close();
       }
       
       
  out.println("<select name=\"select\" id=\""+this.getId()+"\" onChange=\""+this.jsFunction+"\">" );  
  out.println("<option value=\"0\" selected=\"selected\">请选择 </option>");
  out.println(option_str);
  out.println("</select>");
   
}catch (Exception ex)
  {
    throw new JspTagException("IOException:" + ex.toString());
  }
  return super.doEndTag();
}
}
